//
//  BLCommentCell.m
//  Byelone
//
//  Created by Qi Liu on 2021/2/21.
//

#import "BLCommentCell.h"
#import "NSString+BLExe.h"


@interface BLCommentCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nickName;
@property (weak, nonatomic) IBOutlet UILabel *timelabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIView *baseView;

@end

@implementation BLCommentCell

-(void)setReplayModel:(ReplyModel *)replayModel{
    _replayModel = replayModel;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:replayModel.replyUser.avatarUrl]];
    self.nickName.text = replayModel.replyUser.nickname;
    
    NSInteger time = [replayModel.replyTime integerValue]/1000;
    
    self.timelabel.text = [NSString stringToDate:[NSString stringWithFormat:@"%ld",time] Format:@"yyyy-MM-dd hh:mm:ss"];
     [NSString stringToDate:replayModel.replyTime];

    _contentLabel.attributedText = [self generateAttributedStringWithCommentItemModel:replayModel];
}

- (NSMutableAttributedString *)generateAttributedStringWithCommentItemModel:(ReplyModel *)model
{
    NSString *text = @"回复";
    if (model.parentReplyUser != nil) {
        text = [text stringByAppendingString:[NSString stringWithFormat:@"%@:%@",model.parentReplyUser.nickname,model.replyContent]];
    }else{
        NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:model.replyContent];
        return [self setUpAtrrSting:attString];
    }
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:text];
    NSRange defaultRange = [text rangeOfString:model.parentReplyUser.nickname];
    [attString addAttribute:NSForegroundColorAttributeName value:[UIColor chColorWithHexString:@"#6C72F5"] range:defaultRange];

    return [self setUpAtrrSting:attString];
}

-(NSMutableAttributedString *)setUpAtrrSting:(NSMutableAttributedString *)attString{
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 5.0; // 设置行间距
    paragraphStyle.alignment = NSTextAlignmentJustified; //设置两端对齐显示
    [attString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, attString.length)];
    return attString;
}

- (IBAction)deleteClick:(id)sender {
    
    if (_deleteBlock) {
        _deleteBlock(_replayModel,_curIndex);
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    self.iconView.layer.cornerRadius = 15;
    self.iconView.layer.masksToBounds = YES;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    // Initialization code
    
//    [self addShadowToView:_baseView withColor:[UIColor redColor]];
//    self.baseView.layer.cornerRadius = 10;
    [self.baseView setShadowRadius:6 color:BL_COLOR_PURPLE_L(0.12) offset:CGSizeMake(0, 0) opacity:1];
    
    
}
//- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor {
//
//    theView.layer.masksToBounds = NO;
//    // 阴影颜色
//    theView.layer.shadowColor = theColor.CGColor;
//    // 阴影偏移，默认(0, -3)
//    theView.layer.shadowOffset = CGSizeMake(0,0);
//    // 阴影透明度，默认0
//    theView.layer.shadowOpacity = 0.5;
//    // 阴影半径，默认3
//    theView.layer.shadowRadius = 5;
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
